package fl.ass.service.api;

import cmm.comm.facade.upload.api.IUploadApiService;
import cmm.comm.facade.upload.condition.SysUlFilesRecQueryCondition;
import cmm.comm.facade.upload.dto.SysUlFilesRecDTO;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.capital.service.IProfitAndLossApiService;
import cn.fl.project.api.IPrjPrdDtlExtApiService;
import cn.fl.project.constant.PrjPrdDtlConstant;
import cn.fl.project.dto.PrjPrdDtlDTO;
import cn.fl.project.dto.PrjPrdPaySchMDTO;
import cn.fl.project.service.IPrjPrdPaySchMApiService;
import com.alibaba.fastjson.JSON;
import fl.ass.facade.api.IAssTrailCarApi;
import fl.ass.facade.api.ICarDealFlowFactoryApi;
import fl.ass.facade.condition.AssDealRecAmtQueryCondition;
import fl.ass.facade.constant.AssFileConstant;
import fl.ass.facade.constant.InterfaceConstants;
import fl.ass.facade.dto.AssDealRecAmtDTO;
import fl.ass.facade.dto.AssDealSellDTO;
import fl.ass.facade.dto.AssTrailCarDDTO;
import fl.ass.facade.dto.AssTrailCarMDTO;
import fl.ass.facade.dto.MessageDTO;
import fl.ass.facade.dto.ProductStatusLogDTO;
import fl.ass.service.dao.AssTrailCarDMapper;
import fl.ass.service.service.*;
import fl.flow.facade.flow.constant.FlowConstant;
import fl.flow.facade.flow.dto.FlowCompleteParamsDTO;
import fl.flow.facade.flow.service.impl.FlowBusnessServiceImpl;
import fl.flow.service.flow.service.ISysFlowSHService;
import fl.inf.facade.api.IWarrantApiService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 优车处置流程回调接口实现类
 * 
 * @author KANGFENGCUI
 * 
 */
@Service
public class CarDealFlowFactoryApi extends FlowBusnessServiceImpl implements
		ICarDealFlowFactoryApi {

	/**
	 * 流程启动历史服务
	 */
	@Autowired
	private ISysFlowSHService sysFlowSHService;
	/**
	 * 处置-转优车信息表 服务层接口
	 */
	@Autowired
	private IAssDealSellService assDealSellService;
	/**
	 * 拖车明细信息表 服务层接口
	 */
	@Autowired
	private IAssTrailCarDService assTrailCarDService;

	/**
	 * 拖车服务
	 */
	@Autowired
	private IAssTrailCarApi assTrailCarApi;
	/**
	 * 上传下载服务
	 */
	@Autowired
	private IUploadApiService uploadApiService;

	/**
	 * 处置收款表服务
	 */
	@Autowired
	private IAssDealRecAmtService assDealRecAmtService;
	/**
	 * 权证服务
	 */
	@Autowired
	private IWarrantApiService warrantApiService;
	@Autowired
	private AssTrailCarDMapper assTrailCarDMapper;
	@Autowired
	private IAssTrailCarMcrInsStsService assTrailCarMcrInsStsService;
	@Autowired
	private IAssCapFundDecomposeService assCapFundDecomposeService;

    @Autowired
    private IAssParkingMgService assParkingMgService;

	/**
	 * 计算损益
	 */
	@Autowired
	private IProfitAndLossApiService profitAndLossApiService;

	@Autowired
    private IAssTrailCarMService assTrailCarMService;

    @Autowired
    private IPrjPrdPaySchMApiService prjPrdPaySchMApiService;

    @Autowired
    private IPrjPrdDtlExtApiService prjPrdDtlExtApiService;

	@Override
	public Map<String, Object> executeBefore(
			FlowCompleteParamsDTO flowCompleteParamsDTO) throws BaseException {
		Map<String, Object> parms = new HashMap<String, Object>();
		String procDefKey = flowCompleteParamsDTO.getProcDefKey();// 流程KEY
		String taskDefKey = flowCompleteParamsDTO.getTaskDefKey();// 任务KEY
		String branchKey = flowCompleteParamsDTO.getBranchKey();// 分支KEY
		String procInstId = flowCompleteParamsDTO.getProcInstId();// 流程实例ID
		Long id = flowCompleteParamsDTO.getBusinessKey();
		if ("FLOW_0000_019_001".equals(procDefKey)
				&& StringUtils.isNotEmpty(taskDefKey)
				&& StringUtils.isNotEmpty(branchKey)) {
			AssDealSellDTO assDealSellDTO = this.assDealSellService
					.selectById(id);
			// 拖车明细ID (ASS_TRAIL_CAR_D表id)
			Long detailId = assDealSellDTO.getDetailId();
			AssTrailCarDDTO assTrailCarDDTO;
			MessageDTO<String> result;
			if (branchKey.equals("FLOW_0000_019_001_004_001")) {// 销售合同签署通知打款:点击提交
				/**
				 * TODO 1.校验是否填写收付款方（条件：优车变卖ID）
				 */
				if (assDealSellDTO != null) {
					if (StringUtils.isEmpty(assDealSellDTO.getPayeeAccNo())) {
						throw new BaseException(
								BaseExceptionConstant.BASE_EXCEPTION_CODE_603,
								"请填写收款信息.");
					}
				}
				BaseLogUtils.newLogger("查询处置收款表信息Start").setKeys("sellId:" + id).info();
				AssDealRecAmtQueryCondition con = new AssDealRecAmtQueryCondition();
				con.setDataId(id);
				con.setDataTypeCd(InterfaceConstants.DATA_TYPE_CD_1);
				con.setIsDel(BaseConstant.IS_YESNO_NO);
				List<AssDealRecAmtDTO> dtos = assDealRecAmtService.searchList(con);
				if (dtos != null && dtos.size() > 0) {
					for (AssDealRecAmtDTO assDealRecAmtDTO : dtos) {
						if (StringUtils.isEmpty(assDealRecAmtDTO.getPayerBankNm())) {
							throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_603, "请填写实付款方银行信息.");
						}
					}
				}else{
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_601, "处置收款表信息为空,请填写付款方银行信息.");
				}
			}else if(branchKey.equals("FLOW_0000_019_001_007_001")||branchKey.equals("FLOW_0000_019_001_009_002")){//呈报人添加提车人信息：通过;系统管理员审核出库：驳回
				
				MessageDTO<AssTrailCarMDTO> messageDTO  = assTrailCarApi.findAssTrailCarMasterById(assDealSellDTO.getMasterId());
				if (messageDTO != null && messageDTO.getData() != null) {
                    Long recentParkMgId = this.assParkingMgService.getRecentParkMg(messageDTO.getData().getParkId());
                    if (StringUtils.isNotEmpty(recentParkMgId)) {
                        String[] str = {String.valueOf(recentParkMgId)};
                        parms.put("nextAssignee", str);
                    } else {
                        parms.put("nextAssignee", null);
                    }
				}else{
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_603, "查询拖车申请信息失败.");
				}
                if(branchKey.equals("FLOW_0000_019_001_007_001")) {
                    // validateFileUpload(assDealSellDTO, flowCompleteParamsDTO);
                }
			}else if (branchKey.equals("FLOW_0000_019_001_009_001")) {// 系统管理员审核出库:点击通过
				/**
				 * TODO 1.修改出库状态（1、拖车申请表的出库状态为已出库、出库时间 2、修改出库单资料验证状态为验证通过 ）
				 */
				BaseLogUtils.newLogger("修改状态start").setKeys("detailId:" + detailId).info();
				assTrailCarDDTO = assTrailCarDService.selectById(detailId);
				assTrailCarDDTO.setIsOut(InterfaceConstants.IS_OUT_1);
				assTrailCarDDTO.setOutTm(new Date());
				result = this.assTrailCarApi
						.updateAssTrailCarDetailInfo(assTrailCarDDTO);
				if (!result.isSuccess()) {
					throw new BaseException(
							BaseExceptionConstant.BASE_EXCEPTION_CODE_603,
							"修改拖车出库信息失败.");
				}

				SysUlFilesRecQueryCondition qc = new SysUlFilesRecQueryCondition();
				qc.setPkId(String.valueOf(detailId));//主数据ID
				qc.setTabNm(AssFileConstant.ASS_TRAIL_CAR_D_TABNM);//主数据表明
				qc.setSysCd(flowCompleteParamsDTO.getSysCd());//系统代码-必须条件
				qc.setCfgCd(AssFileConstant.ASS_TRAIL_CAR_CFGCD);//拖车模块
				qc.setCfgDtlCd(AssFileConstant.ASS_TRAIL_CAR_CFGDTLCD_40);//出库单
				List<SysUlFilesRecDTO> list = this.uploadApiService.searchSysUlFilesRecList(qc);
				if (list == null || list.size() < 1) {
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_601, "更新出库单验证状态失败--请先上传出库单附件.");
				}else{
                    qc.setAudStsCd(AssFileConstant.AUD_STS_CD_1);//验证通过
                    boolean flag = this.uploadApiService.modifyAudStsCd(qc);
                    if (!flag) {
                        throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_603, "更新出库单验证状态失败.");
                    }
				}
			} else if (branchKey.equals("FLOW_0000_019_001_011_001")) {// 财务做账:点击通过
				/**
				 * TODO 1.记录处置状态（1、优车处置表的流程状态为通过 2、拖车申请表的拖车处置状态为优车已处置  3、支付表状态为优车已处置、插入结清时间）
				 *       2.流程结束：通过
				 */
				BaseLogUtils.newLogger("修改状态start").setKeys("sellId:" + id, "detailId:" + detailId).info();
				assDealSellDTO.setFlowStatusCd(InterfaceConstants.FLOW_STATUS_CD_3);// 流程状态：流程通过
				if (!this.assDealSellService.modify(assDealSellDTO)) {
					throw new BaseException(
							BaseExceptionConstant.BASE_EXCEPTION_CODE_603,
							"更新优车处置表流程状态失败.");
				}

				assTrailCarDDTO = assTrailCarDService.selectById(detailId);
				assTrailCarDDTO.setDealStsCd(InterfaceConstants.DEAL_STATUS_CD_14);// 处置状态：优车已处置（优车已变卖）
				result = this.assTrailCarApi
						.updateAssTrailCarDetailInfo(assTrailCarDDTO);
				if (!result.isSuccess()) {
					throw new BaseException(
							BaseExceptionConstant.BASE_EXCEPTION_CODE_603,
							"修改拖车处置状态失败.");
				}

				BaseLogUtils.newLogger("修改支付表状态start").setKeys("paySchId:" + assTrailCarDDTO.getPaySchId()).info();
				List<ProductStatusLogDTO> proList = new ArrayList<ProductStatusLogDTO>();
				ProductStatusLogDTO proDTO = new ProductStatusLogDTO();
				proDTO.setCurrentStatus(InterfaceConstants.PAY_STATUS_CD_S01060203010101);
				proDTO.setPrjPrdId(assTrailCarDDTO.getPrjPrdDtlId());
				proDTO.setOpCode(InterfaceConstants.OP_CODE_OP0032);
				proDTO.setProcessInstanceCode(procDefKey);
				proDTO.setProcessInstanceId(procInstId);
				proList.add(proDTO);
				result = this.assTrailCarApi.updatePayStatus(proList);
				if (!result.isSuccess()) {
					throw new BaseException(
							BaseExceptionConstant.BASE_EXCEPTION_CODE_603,
							"更新支付表状态失败.");
				}
                BaseLogUtils.newLogger("修改支付表状态end").setKeys("paySchId:" + assTrailCarDDTO.getPaySchId()).info();
//				BaseLogUtils.newLogger("修改小贷保险支付表状态：start").info();
//				assTrailCarMcrInsStsService.updateMrcInsSts(assTrailCarDDTO.getCstId());
//                BaseLogUtils.newLogger("修改小贷保险支付表状态：end").info();
                BaseLogUtils.newLogger("支付表状态为优车已处置，向权证接口传送数据start").setKeys("masterId:" + assTrailCarDDTO.getMasterId(), "detailId:" + assTrailCarDDTO.getId()).info();
				Long projectId = assTrailCarDDTO.getPrjId();
				String paylistCode = assTrailCarDDTO.getPaySchNo();//支付表编号
				String status = InterfaceConstants.PAY_STATUS_CD_S01060203010101;//优车已处置
				Date endDate = null;//结清日期可以为空
				fl.inf.facade.dto.MessageDTO<String> response = warrantApiService.changePayStatus(projectId, paylistCode, status, endDate);
				if (!response.isSuccess()) {
					throw new BaseException(
							BaseExceptionConstant.BASE_EXCEPTION_CODE_603,
							"===向权证接口传送数据失败===.");
				}
                BaseLogUtils.newLogger("支付表状态为优车已处置，向权证接口传送数据end").info();
				// 同步修改疫情支付表状态
                ProductStatusLogDTO productStatusLogDTO = new ProductStatusLogDTO();
                productStatusLogDTO.setPaySchId(assTrailCarDDTO.getPaySchId());
                productStatusLogDTO.setPrjPrdId(assTrailCarDDTO.getPrjPrdDtlId());
                productStatusLogDTO.setCurrentStatus(PrjPrdDtlConstant.CODE_PRJ_PRD_STS_CD_22);
                productStatusLogDTO.setOpCode(InterfaceConstants.OP_CODE_OP0032);
                productStatusLogDTO.setProcessInstanceCode(flowCompleteParamsDTO.getProcDefKey());
                productStatusLogDTO.setProcessInstanceId(flowCompleteParamsDTO.getProcInstId());
				this.assTrailCarMService.updateYQPrdStsCdByFlow(productStatusLogDTO);
                /**
                 * 若当前支付表存在未结清YQ项目，则需针对当前支付表关联的资金是否存在剩余可用资金进行校验。
                 */
                boolean check = this.assTrailCarMService.checkRestFund4YQ(assTrailCarDDTO.getPrjPrdDtlId(), assTrailCarDDTO.getCstId());
                if (false == check) {
                    throw new BaseException("存在剩余可用资金，请分解至关联YQ支付表");
                }
                // 处置时，若启用是赎回或备份支付表，则新增一条PRJ_PRD_DTL数据，详见：REQ-12146
                List<PrjPrdPaySchMDTO> prjPrdPaySchMDTOS = this.prjPrdPaySchMApiService.selectEnabledListByPaySchId(assTrailCarDDTO.getPaySchId());
                if (CollectionUtils.isNotEmpty(prjPrdPaySchMDTOS)) {
                    PrjPrdPaySchMDTO prjPrdPaySchMDTO = prjPrdPaySchMDTOS.get(0);
                    PrjPrdDtlDTO dto = new PrjPrdDtlDTO();
                    dto.setPaySchId(prjPrdPaySchMDTO.getId());
                    dto.setStlDt(Calendar.getInstance().getTime());
                    dto.setPrdStsCd(InterfaceConstants.PAY_STATUS_CD_S01060203010101);
                    dto.setOpCode(InterfaceConstants.OP_CODE_OP0032);
                    this.prjPrdDtlExtApiService.insertPrjPrdDtlWhenSettledBFAndSH(dto);
                }
			} else if (branchKey.equals("FLOW_0000_019_001_002_001")
					|| branchKey.equals("FLOW_0000_019_001_004_002")) {// 发起人、销售合同签署通知打款:点击不通过，流程结束
				/**
				 * TODO 1.优车处置表流程状态：不通过，拖车申请表处置状态为已转优车，支付表状态为已转优车 2.流程结束：不通过
				 */
                BaseLogUtils.newLogger("修改状态start").setKeys("sellId:" + id, "detailId:" + detailId).info();
				assDealSellDTO.setFlowStatusCd(InterfaceConstants.FLOW_STATUS_CD_4);// 流程状态：流程不通过
				if (!this.assDealSellService.modify(assDealSellDTO)) {
					throw new BaseException(
							BaseExceptionConstant.BASE_EXCEPTION_CODE_603,
							"更新优车处置表流程状态失败.");
				}

				assTrailCarDDTO = assTrailCarDService.selectById(detailId);
				assTrailCarDDTO.setDealStsCd(InterfaceConstants.DEAL_STATUS_CD_15);// 处置状态：优车处置不通过
				result = this.assTrailCarApi
						.updateAssTrailCarDetailInfo(assTrailCarDDTO);
				if (!result.isSuccess()) {
					throw new BaseException(
							BaseExceptionConstant.BASE_EXCEPTION_CODE_603,
							"修改拖车处置状态失败.");
				}
                BaseLogUtils.newLogger("修改状态end").setKeys("sellId:" + id, "detailId:" + detailId).info();

                BaseLogUtils.newLogger("修改支付表状态start").setKeys("paySchId:" + assTrailCarDDTO.getPaySchId()).info();
				List<ProductStatusLogDTO> proList = new ArrayList<ProductStatusLogDTO>();
				ProductStatusLogDTO proDTO = new ProductStatusLogDTO();
				proDTO.setCurrentStatus(InterfaceConstants.PAY_STATUS_CD_S0106020301);
				proDTO.setPrjPrdId(assTrailCarDDTO.getPrjPrdDtlId());
				proDTO.setOpCode(InterfaceConstants.OP_CODE_OP0030);
				proDTO.setProcessInstanceCode(procDefKey);
				proDTO.setProcessInstanceId(procInstId);
				proList.add(proDTO);
				result = this.assTrailCarApi.updatePayStatus(proList);
				if (!result.isSuccess()) {
					throw new BaseException(
							BaseExceptionConstant.BASE_EXCEPTION_CODE_603,
							"更新支付表状态失败.");
				}
                BaseLogUtils.newLogger("修改支付表状态end").setKeys("paySchId:" + assTrailCarDDTO.getPaySchId()).info();

                BaseLogUtils.newLogger("支付表状态为已拖回，向权证接口传送数据start").setKeys("masterId:" + assTrailCarDDTO.getMasterId(), "detailId:" + assTrailCarDDTO.getId()).info();
				Long projectId = assTrailCarDDTO.getPrjId();
				String paylistCode = assTrailCarDDTO.getPaySchNo();//支付表编号
				String status = InterfaceConstants.PAY_STATUS_CD_S0106020301;//已转优车
				Date endDate = null;//结清日期可以为空
				fl.inf.facade.dto.MessageDTO<String> response = warrantApiService.changePayStatus(projectId, paylistCode, status, endDate);
				if (!response.isSuccess()) {
					throw new BaseException(
							BaseExceptionConstant.BASE_EXCEPTION_CODE_603,
							"===向权证接口传送数据失败===.");
				}
                BaseLogUtils.newLogger("支付表状态为已拖回，向权证接口传送数据end").info();
                // 同步修改疫情支付表状态
                ProductStatusLogDTO productStatusLogDTO = new ProductStatusLogDTO();
                productStatusLogDTO.setPaySchId(assTrailCarDDTO.getPaySchId());
                productStatusLogDTO.setPrjPrdId(assTrailCarDDTO.getPrjPrdDtlId());
                productStatusLogDTO.setCurrentStatus(PrjPrdDtlConstant.CODE_PRJ_PRD_STS_CD_20);
                productStatusLogDTO.setOpCode(InterfaceConstants.OP_CODE_OP0029);
                productStatusLogDTO.setProcessInstanceCode(flowCompleteParamsDTO.getProcDefKey());
                productStatusLogDTO.setProcessInstanceId(flowCompleteParamsDTO.getProcInstId());
                this.assTrailCarMService.updateYQPrdStsCdByFlow(productStatusLogDTO);
			}else if(branchKey.equals("FLOW_0000_019_001_006_001")){//财务部确认来款
				if (StringUtils.isEmpty(assDealSellDTO.getPickCarNm())||StringUtils.isEmpty(assDealSellDTO.getPickCarCd())) {
					parms.put("PICK_INFO", BaseConstant.IS_YESNO_NO);
				}else{
					parms.put("PICK_INFO", BaseConstant.IS_YESNO_YES);
					MessageDTO<AssTrailCarMDTO> assTrailCarMDTO = assTrailCarApi.findAssTrailCarMasterById(assDealSellDTO.getMasterId());
					if (assTrailCarMDTO != null && assTrailCarMDTO.getData() != null) {
                        Long recentParkMgId = this.assParkingMgService.getRecentParkMg(assTrailCarMDTO.getData().getParkId());
                        if (StringUtils.isNotEmpty(recentParkMgId)) {
                            String[] str = {String.valueOf(recentParkMgId)};
                            parms.put("nextAssignee", str);
                        } else {
                            parms.put("nextAssignee", null);
                        }
					}else{
						throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_603, "优车处置流程(CarDealFlowFactoryApi)->财务部确认来款节点->点击通过，动态设置节点处理人,查询拖车信息明细表失败");
					}
				}

				boolean theNewestFlow = assCapFundDecomposeService.isTheNewestFlow(flowCompleteParamsDTO);
				if (theNewestFlow) {
					// 资金分解+计算损益
					assCapFundDecomposeService.capFundDecompose(flowCompleteParamsDTO);
				}
			} else if ("FLOW_0000_019_001_002_002".equals(branchKey)) {
			    // 提交（发起人）
                // validateFileUpload(assDealSellDTO, flowCompleteParamsDTO);
            }
		}

		return parms;
	}

	@Override
	public void executeAfter(FlowCompleteParamsDTO flowCompleteParamsDTO)
			throws BaseException {
		String branchKey = flowCompleteParamsDTO.getBranchKey();//分支KEY
		switch (branchKey) {
		case "FLOW_0000_019_001_011_001"://财务做账:点击通过 流程结束
			this.pass(flowCompleteParamsDTO);
			break;
		case "FLOW_0000_019_001_002_001":// 发起人:点击不通过
			this.noPass(flowCompleteParamsDTO);
			break;	
		case "FLOW_0000_019_001_004_002"://销售合同签署通知打款:不通过 
			this.noPass(flowCompleteParamsDTO);
			break;
		default:
			break;
	   }
	}

    /**
     * 校验拖车处置材料是否上传
     *
     * @param assDealSellDTO
     * @param flowCompleteParamsDTO
     */
    private void validateFileUpload(AssDealSellDTO assDealSellDTO, FlowCompleteParamsDTO flowCompleteParamsDTO) {

        SysUlFilesRecQueryCondition qc = new SysUlFilesRecQueryCondition();
        qc.setPkId(String.valueOf(assDealSellDTO.getId()));//主数据ID
        qc.setTabNm(AssFileConstant.ASS_DEAL_SELL_TABNM);//主数据表明
        qc.setSysCd(flowCompleteParamsDTO.getSysCd());//系统代码-必须条件
        qc.setCfgCd("ASS008");
        qc.setCfgDtlCd("1");
        List<SysUlFilesRecDTO> list = this.uploadApiService.searchSysUlFilesRecList(qc);
        BaseLogUtils.newLogger("拖车处置查询文件上传记录为1").setKeys("list:" + JSON.toJSONString(list)).info();
        if (CollectionUtils.isEmpty(list)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_601, "购车方签署《购车合同》");
        }
        qc.setCfgDtlCd("2");
        list = this.uploadApiService.searchSysUlFilesRecList(qc);
        BaseLogUtils.newLogger("拖车处置查询文件上传记录为2").setKeys("list:" + JSON.toJSONString(list)).info();
        if (CollectionUtils.isEmpty(list)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_601, "购车方签署《代偿结清协议》");
        }
    }

	@Override
	public String getFlowBusinessActMgrOrgCd(
			FlowCompleteParamsDTO flowCompleteParamsDTO) throws BaseException {
		Long id = flowCompleteParamsDTO.getBusinessKey();
		AssDealSellDTO assDealSellDTO = this.assDealSellService
				.selectById(id);
		//拖车明细数据
		List<AssTrailCarDDTO> assTrailCarDDTOList = assTrailCarApi.findTrailCarDetailListById(assDealSellDTO.getMasterId()).getDatas();
		String cstMgrOrgCd = "";
		if (assTrailCarDDTOList != null && assTrailCarDDTOList.size() > 0) {
			Long prjId = assTrailCarDDTOList.get(0).getPrjId();
            BaseLogUtils.newLogger("流程回调实现类获取项目客户经理组织架构代码开始").setKeys("taskId:" + flowCompleteParamsDTO.getTaskId(), "prjId:" + prjId).info();
			if(null!=prjId){
			    cstMgrOrgCd = assTrailCarDMapper.selectCstMgrOrgCd(prjId);
				if (null == cstMgrOrgCd || cstMgrOrgCd.equals("")) {
                    BaseLogUtils.newLogger("根据ID未获取到业务数据!").info();
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_601, "根据ID未获取到业务数据!");
				}
                BaseLogUtils.newLogger("流程回调实现类获取项目客户经理组织架构代码结束").setKeys("taskId:" + flowCompleteParamsDTO.getTaskId(), "prjId:" + prjId, "cstMgrOrgCd:" + cstMgrOrgCd).info();
				return cstMgrOrgCd;
			}
		}
        BaseLogUtils.newLogger("流程接口回调>>返回项目客户经理组织架构>>未找到!").info();
		return super.getFlowBusinessActMgrOrgCd(flowCompleteParamsDTO);
	}

	/**
	 * 流程结束:通过
	 * 
	 * @param flowCompleteParamsDTO
	 * @throws BaseException
	 */
	private void pass(FlowCompleteParamsDTO flowCompleteParamsDTO)
			throws BaseException {
		this.sysFlowSHService.modifyAudStsCd(
				InterfaceConstants.ASS_FLOW_S_H_ASS,
				FlowConstant.FLOW_CHECK_STATE_PASS, new Date(), new Date(),
				flowCompleteParamsDTO.getCrtUsrId(),
				flowCompleteParamsDTO.getBusinessKey(),
				flowCompleteParamsDTO.getProcDefKey(),
				flowCompleteParamsDTO.getProcDefId(),
				flowCompleteParamsDTO.getSysCd(),
				flowCompleteParamsDTO.getProcInstId());
	}

	/**
	 * 流程结束:不通过
	 * 
	 * @param flowCompleteParamsDTO
	 * @throws BaseException
	 */
	private void noPass(FlowCompleteParamsDTO flowCompleteParamsDTO)
			throws BaseException {
		this.sysFlowSHService.modifyAudStsCd(
				InterfaceConstants.ASS_FLOW_S_H_ASS,
				FlowConstant.FLOW_CHECK_STATE_NO_PASS, new Date(), new Date(),
				flowCompleteParamsDTO.getCrtUsrId(),
				flowCompleteParamsDTO.getBusinessKey(),
				flowCompleteParamsDTO.getProcDefKey(),
				flowCompleteParamsDTO.getProcDefId(),
				flowCompleteParamsDTO.getSysCd(),
				flowCompleteParamsDTO.getProcInstId());
	}

}
